<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class Register extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'name'=>'required|min:6|max:25',
            'phone' => ['required','unique:users','regex:/^((13[0-9])|(15[^4])|(166)|(17[0-8])|(18[0-9])|(19[8-9])|(147)|(145))\\d{8}$/'],
            'password' => 'required|confirmed|min:6|max:25',
            'sec_password' => 'required|min:6|max:25',
            'phone_code'=>'required',
            'register_code'=>'exists:users,register_code',
        ];
    }

    public function messages()
    {
        return [
            'name.required'=>'请输入用户名',
            'name.min'=>'用户名最少6位',
            'name.max'=>'用户名最多25位',

            'phone.required' => '请输入手机号',
            'phone.unique' => '该手机号已被占用',
            'phone.regex' => '手机号格式错误',

            'password.required'=>'请输入密码',
            'password.confirmed'=>'两次密码输入不一致',
            'password.min'=>'密码最少6位',
            'password.max'=>'密码最多25位',

            'sec_password.required'=>'请输入安全密码',
            'sec_password.min'=>'安全密码最少6位',
            'sec_password.max'=>'安全密码最多25位',

            'phone_code.required'=>'请输入验证码',

            'register_code.required'=>'请输入邀请码',
            'register_code.exists'=>'该邀请码不存在',
        ];
    }
}
